namespace SWTORLogDb.Migrations
{
    using System.Data.Entity.Migrations;
    
    public partial class Initial : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Players",
                c => new
                    {
                        PlayerId = c.Int(nullable: false, identity: true),
                        Name = c.String(maxLength: 100),
                        NickName = c.String(maxLength: 100),
                        Created = c.DateTime(nullable: false),
                        CreatedUser = c.String(maxLength: 30),
                        Modified = c.DateTime(nullable: false),
                        ModifyUser = c.String(maxLength: 30),
                        RowVersion = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"),
                    })
                .PrimaryKey(t => t.PlayerId);
            
            CreateTable(
                "dbo.Characters",
                c => new
                    {
                        CharacterId = c.Int(nullable: false, identity: true),
                        Race = c.Int(nullable: false),
                        Class = c.Int(nullable: false),
                        SubClass = c.Int(nullable: false),
                        Level = c.Int(nullable: false),
                        SocialLevel = c.Int(nullable: false),
                        ValorLevel = c.Int(nullable: false),
                        GuildId = c.Int(nullable: false),
                        ServerId = c.Int(nullable: false),
                        PlayerId = c.Int(nullable: false),
                        Created = c.DateTime(nullable: false),
                        CreatedUser = c.String(maxLength: 30),
                        Modified = c.DateTime(nullable: false),
                        ModifyUser = c.String(maxLength: 30),
                        RowVersion = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"),
                    })
                .PrimaryKey(t => t.CharacterId)
                .ForeignKey("dbo.Guilds", t => t.GuildId)
                .ForeignKey("dbo.Servers", t => t.ServerId)
                .ForeignKey("dbo.Players", t => t.PlayerId)
                .Index(t => t.GuildId)
                .Index(t => t.ServerId)
                .Index(t => t.PlayerId);
            
            CreateTable(
                "dbo.Guilds",
                c => new
                    {
                        GuildId = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 24),
                        ServerId = c.Int(nullable: false),
                        Created = c.DateTime(nullable: false),
                        CreatedUser = c.String(maxLength: 30),
                        Modified = c.DateTime(nullable: false),
                        ModifyUser = c.String(maxLength: 30),
                        RowVersion = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"),
                    })
                .PrimaryKey(t => t.GuildId)
                .ForeignKey("dbo.Servers", t => t.ServerId)
                .Index(t => t.ServerId);
            
            CreateTable(
                "dbo.Servers",
                c => new
                    {
                        ServerId = c.Int(nullable: false, identity: true),
                        Name = c.String(maxLength: 50),
                        Type = c.Int(nullable: false),
                        IsRolePlaying = c.Boolean(nullable: false),
                        Created = c.DateTime(nullable: false),
                        CreatedUser = c.String(maxLength: 30),
                        Modified = c.DateTime(nullable: false),
                        ModifyUser = c.String(maxLength: 30),
                        RowVersion = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"),
                    })
                .PrimaryKey(t => t.ServerId);
            
            CreateTable(
                "dbo.Encounters",
                c => new
                    {
                        EncounterId = c.Int(nullable: false, identity: true),
                        RowVersion = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"),
                        CharacterId = c.Int(),
                        OperationId = c.Int(),
                        Discriminator = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => t.EncounterId)
                .ForeignKey("dbo.Characters", t => t.CharacterId)
                .ForeignKey("dbo.Operations", t => t.OperationId)
                .Index(t => t.CharacterId)
                .Index(t => t.OperationId);
            
            CreateTable(
                "dbo.CombatLogEntries",
                c => new
                    {
                        CombatLogEntryId = c.Int(nullable: false, identity: true),
                        EncounterId = c.Int(nullable: false),
                        EntryTimestamp = c.DateTime(nullable: false),
                        Source = c.String(maxLength: 100),
                        SourceIsPlayer = c.Boolean(nullable: false),
                        Target = c.String(maxLength: 100),
                        TargetIsPlayer = c.Boolean(nullable: false),
                        AbilityName = c.String(maxLength: 200),
                        AbilityId = c.Long(nullable: false),
                        Event = c.String(maxLength: 200),
                        EventId = c.Long(nullable: false),
                        Effect = c.String(maxLength: 200),
                        EffectId = c.Long(nullable: false),
                        Amount = c.Int(),
                        Critical = c.Boolean(nullable: false),
                        Threat = c.Int(nullable: false),
                        RowVersion = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"),
                    })
                .PrimaryKey(t => t.CombatLogEntryId)
                .ForeignKey("dbo.Encounters", t => t.EncounterId)
                .Index(t => t.EncounterId);
            
            CreateTable(
                "dbo.OperationAttendances",
                c => new
                    {
                        OperationAttendanceId = c.Int(nullable: false, identity: true),
                        CharacterId = c.Int(nullable: false),
                        OperationId = c.Int(nullable: false),
                        Status = c.Int(nullable: false),
                        Role = c.Int(nullable: false),
                        Created = c.DateTime(nullable: false),
                        CreatedUser = c.String(maxLength: 30),
                        Modified = c.DateTime(nullable: false),
                        ModifyUser = c.String(maxLength: 30),
                        RowVersion = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"),
                    })
                .PrimaryKey(t => t.OperationAttendanceId)
                .ForeignKey("dbo.Characters", t => t.CharacterId)
                .ForeignKey("dbo.Operations", t => t.OperationId)
                .Index(t => t.CharacterId)
                .Index(t => t.OperationId);
            
            CreateTable(
                "dbo.Operations",
                c => new
                    {
                        OperationId = c.Int(nullable: false, identity: true),
                        OperationZoneId = c.Int(nullable: false),
                        Mode = c.Int(nullable: false),
                        PlayerCount = c.Int(nullable: false),
                        KeepOnlyBossFights = c.Boolean(nullable: false),
                        StartDateTime = c.DateTime(nullable: false),
                        EndDateTime = c.DateTime(nullable: false),
                        OpenLogMergerDateTime = c.DateTime(nullable: false),
                        Status = c.Int(nullable: false),
                        Created = c.DateTime(nullable: false),
                        CreatedUser = c.String(maxLength: 30),
                        Modified = c.DateTime(nullable: false),
                        ModifyUser = c.String(maxLength: 30),
                        RowVersion = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"),
                    })
                .PrimaryKey(t => t.OperationId)
                .ForeignKey("dbo.OperationZones", t => t.OperationZoneId)
                .Index(t => t.OperationZoneId);
            
            CreateTable(
                "dbo.OperationZones",
                c => new
                    {
                        OperationZoneId = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false),
                        ValidModes = c.Int(nullable: false),
                        Created = c.DateTime(nullable: false),
                        CreatedUser = c.String(maxLength: 30),
                        Modified = c.DateTime(nullable: false),
                        ModifyUser = c.String(maxLength: 30),
                        RowVersion = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"),
                    })
                .PrimaryKey(t => t.OperationZoneId);
            
            CreateTable(
                "dbo.OperationBosses",
                c => new
                    {
                        OperationBossId = c.Int(nullable: false, identity: true),
                        Name = c.String(maxLength: 100),
                        LogNames = c.String(),
                        Created = c.DateTime(nullable: false),
                        CreatedUser = c.String(maxLength: 30),
                        Modified = c.DateTime(nullable: false),
                        ModifyUser = c.String(maxLength: 30),
                        RowVersion = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"),
                        OperationZone_OperationZoneId = c.Int(),
                    })
                .PrimaryKey(t => t.OperationBossId)
                .ForeignKey("dbo.OperationZones", t => t.OperationZone_OperationZoneId)
                .Index(t => t.OperationZone_OperationZoneId);
            
            CreateTable(
                "dbo.CharacterCrewSkills",
                c => new
                    {
                        CharacterCrewSkillId = c.Int(nullable: false, identity: true),
                        CharacterId = c.Int(nullable: false),
                        CrewSkill = c.Int(nullable: false),
                        Level = c.Int(nullable: false),
                        Created = c.DateTime(nullable: false),
                        CreatedUser = c.String(maxLength: 30),
                        Modified = c.DateTime(nullable: false),
                        ModifyUser = c.String(maxLength: 30),
                        RowVersion = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"),
                    })
                .PrimaryKey(t => t.CharacterCrewSkillId)
                .ForeignKey("dbo.Characters", t => t.CharacterId)
                .Index(t => t.CharacterId);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.CharacterCrewSkills", new[] { "CharacterId" });
            DropIndex("dbo.OperationBosses", new[] { "OperationZone_OperationZoneId" });
            DropIndex("dbo.Operations", new[] { "OperationZoneId" });
            DropIndex("dbo.OperationAttendances", new[] { "OperationId" });
            DropIndex("dbo.OperationAttendances", new[] { "CharacterId" });
            DropIndex("dbo.CombatLogEntries", new[] { "EncounterId" });
            DropIndex("dbo.Encounters", new[] { "OperationId" });
            DropIndex("dbo.Encounters", new[] { "CharacterId" });
            DropIndex("dbo.Guilds", new[] { "ServerId" });
            DropIndex("dbo.Characters", new[] { "PlayerId" });
            DropIndex("dbo.Characters", new[] { "ServerId" });
            DropIndex("dbo.Characters", new[] { "GuildId" });
            DropForeignKey("dbo.CharacterCrewSkills", "CharacterId", "dbo.Characters");
            DropForeignKey("dbo.OperationBosses", "OperationZone_OperationZoneId", "dbo.OperationZones");
            DropForeignKey("dbo.Operations", "OperationZoneId", "dbo.OperationZones");
            DropForeignKey("dbo.OperationAttendances", "OperationId", "dbo.Operations");
            DropForeignKey("dbo.OperationAttendances", "CharacterId", "dbo.Characters");
            DropForeignKey("dbo.CombatLogEntries", "EncounterId", "dbo.Encounters");
            DropForeignKey("dbo.Encounters", "OperationId", "dbo.Operations");
            DropForeignKey("dbo.Encounters", "CharacterId", "dbo.Characters");
            DropForeignKey("dbo.Guilds", "ServerId", "dbo.Servers");
            DropForeignKey("dbo.Characters", "PlayerId", "dbo.Players");
            DropForeignKey("dbo.Characters", "ServerId", "dbo.Servers");
            DropForeignKey("dbo.Characters", "GuildId", "dbo.Guilds");
            DropTable("dbo.CharacterCrewSkills");
            DropTable("dbo.OperationBosses");
            DropTable("dbo.OperationZones");
            DropTable("dbo.Operations");
            DropTable("dbo.OperationAttendances");
            DropTable("dbo.CombatLogEntries");
            DropTable("dbo.Encounters");
            DropTable("dbo.Servers");
            DropTable("dbo.Guilds");
            DropTable("dbo.Characters");
            DropTable("dbo.Players");
        }
    }
}
